package com.dcm.item.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.exception.MyException;
import com.dcm.item.entity.CommentEntity;
import com.dcm.item.service.CommentService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: liutaoran
 * @date: 2021-03-25 21:11
 */
@Api(tags = "CommentController")
@RestController
@RequestMapping("/comment")
@EnableResponseBodyAdvice
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 查询
     *
     * @return
     */
    @GetMapping("/findAll")
    public List<CommentEntity> findAll() {
        return commentService.findAll();
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/findOne")
    public CommentEntity findOne(@RequestParam(value = "id",required = false) Long id) throws MyException {

        return commentService.findOne(id);

    }

    /**
     * 根据id删除
     *
     * @param id
     */
    @DeleteMapping("/delete")
    public void delete(@RequestParam(value = "id", required = false) Long id) throws MyException {
        commentService.delete(id);

    }

    /**
     * 修改
     *
     * @param commentEntity
     */
    @PutMapping("/update")
    public void update(@RequestBody CommentEntity commentEntity) throws MyException {
        commentService.update(commentEntity);
    }


    /**
     * 新增
     *
     * @param commentEntity
     * @throws MyException
     */
    @PostMapping("/insert")
    public void insert(@RequestBody CommentEntity commentEntity) throws MyException {
        commentService.insert(commentEntity);
    }


    /**
     * 根据用户名模糊查询
     *
     * @param userName
     * @return
     */
    @GetMapping("/findByUserName")
    public List<CommentEntity> findByUserName(@RequestParam(value = "userName", required = false) String userName) {
        return commentService.findByUserName(userName);
    }

    /**
     * 根据商品名称查询
     *
     * @param itemName
     * @return
     */
    @GetMapping("/findByItemName")
    public List<CommentEntity> findByItemName(@RequestParam(value = "itemName", required = false) String itemName) {
        return commentService.findByItemName(itemName);
    }

    @ApiOperation("分页")
    @GetMapping("findPage")
    public PageInfo<CommentEntity> findPage(@RequestParam(value = "pageSize", required = false) Integer pageSize,
                                            @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return commentService.findPage(currentPage, pageSize);
    }

    /**
     * 回复状态查询
     *
     * @param status
     * @return
     */
    @GetMapping("/findByStatus")
    public List<CommentEntity> findByStatus(@RequestParam String status) {
        return commentService.findByStatus(status);
    }

    /**
     * 今天
     *
     * @return
     */
    @GetMapping("/today")
    public List<CommentEntity> today() {
        return commentService.today();
    }

    /**
     * 昨天
     *
     * @return
     */
    @GetMapping("/yesterday")
    public List<CommentEntity> yesterday() {
        return commentService.yesterday();
    }

    /**
     * 7天
     *
     * @return
     */
    @GetMapping("/days")
    public List<CommentEntity> days() {
        return commentService.days();
    }

    /**
     * 本月
     *
     * @return
     */
    @GetMapping("/month")
    public List<CommentEntity> month() {
        return commentService.month();
    }

    /**
     * 本年
     *
     * @return
     */
    @GetMapping("/year")
    public List<CommentEntity> year() {
        return commentService.year();
    }
}
